import loadable from '@loadable/component';
import {Environment} from "relay-runtime";
import {loadQuery} from "react-relay/hooks";
import IspGuideQuery from "./__generated__/IspGuideQuery.graphql";

/**
 * 多层次的路由器。
 * 多个一级路由的集合：
一级路由层次不需要预加载数据的页面。
 * */
export default function secondRouter(environment: Environment) {
  return (
      {
        path: '/search',
        component: loadable( () => import('./SearchMain')),
        routes:[
            {
                path: '/search/report',
                exact: true,
                component: loadable( () => import('./ReportGuide')),

            },
            {
                path: '/search/isp/:ispId',
                exact: true,
                component: loadable( () => import('./IspGuide')),
                prepare: (params:any) => {
                    console.log(`路由历史state37-点击路由params:`, params, window.history.state);
                    return {
                        query: loadQuery(
                            environment as any,
                            IspGuideQuery as any,
                            {
                                id: params.ispId,
                            },
                            { fetchPolicy: 'store-or-network' },
                        ),
                    };
                },
            },
        ],
      }
  );
}

